// 仓库
import {
	defineStore
} from "pinia";

import {
	GetShoppingCart,GetUserFromId
} from '../apis/api.js'



const useCartStore = defineStore('cart', {
	state: () => {
		return {
			badge: 0,
			addressId:''
		}
	},
	actions: {
		async initBadge(item) {
			console.log(item);
			const result = await GetShoppingCart(item)
			console.log(result.data.length);
			this.badge = result.data.length
		},
		updateBadge(userId) {
			this.initBadge(userId);
		},
		async initAddressId(item){
			const result=await  GetUserFromId(item)
			this.addressId=result.data[0].address_id
		}
	},
	getters: {

	}
});

export default useCartStore;